<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>美味外卖 - 您的专属订餐平台</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="js/auth.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
        }

        :root {
            --primary: #ff6b00;
            --primary-light: #ff8c3a;
            --secondary: #3c9eff;
            --dark: #333;
            --gray: #666;
            --light-gray: #f5f5f5;
            --white: #fff;
            --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
            --radius: 12px;
        }

        body {
            background-color: #f8f8f8;
            color: var(--dark);
            padding-bottom: 70px;
        }

        /* 顶部导航 */
        .header {
            position: sticky;
            top: 0;
            background: var(--white);
            padding: 12px 16px;
            box-shadow: var(--shadow);
            z-index: 100;
        }

        .location-bar {
            display: flex;
            align-items: center;
            margin-bottom: 12px;
        }

        .location {
            flex: 1;
            font-weight: 600;
            font-size: 18px;
        }

        .location i {
            color: var(--primary);
            margin-right: 6px;
        }

        .search-bar {
            display: flex;
            background: var(--light-gray);
            border-radius: 24px;
            padding: 10px 16px;
            align-items: center;
        }

        .search-bar i {
            color: var(--gray);
            margin-right: 8px;
        }

        .search-bar input {
            border: none;
            background: transparent;
            flex: 1;
            font-size: 14px;
            outline: none;
        }

        /* 促销区域 */
        .promo-section {
            padding: 16px;
            background: linear-gradient(135deg, #fff8f0, #fff);
        }

        .promo-title {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 12px;
        }

        .promo-title h2 {
            font-size: 18px;
            color: var(--dark);
        }

        .promo-title a {
            color: var(--gray);
            font-size: 14px;
            text-decoration: none;
        }

        .promo-cards {
            display: flex;
            gap: 12px;
            overflow-x: auto;
            padding-bottom: 8px;
        }

        .promo-card {
            flex: 0 0 280px;
            background: var(--white);
            border-radius: var(--radius);
            padding: 16px;
            box-shadow: var(--shadow);
        }

        .promo-card h3 {
            font-size: 16px;
            margin-bottom: 8px;
            color: var(--dark);
        }

        .promo-card p {
            font-size: 13px;
            color: var(--gray);
            margin-bottom: 12px;
        }

        .promo-card .tag {
            display: inline-block;
            background: #fff0e6;
            color: var(--primary);
            font-size: 12px;
            padding: 4px 8px;
            border-radius: 4px;
        }

        /* 分类导航 */
        .category-section {
            padding: 16px;
            background: var(--white);
            margin: 8px 0;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
        }

        .categories {
            display: grid;
            grid-template-columns: repeat(5, 1fr);
            gap: 16px;
            text-align: center;
        }

        .category {
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .category-icon {
            width: 48px;
            height: 48px;
            background: var(--light-gray);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 8px;
        }

        .category-icon i {
            font-size: 20px;
            color: var(--primary);
        }

        .category-name {
            font-size: 12px;
            color: var(--dark);
        }

        /* 商家列表 */
        .restaurant-section {
            padding: 0 16px;
        }

        .section-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin: 20px 0 16px;
        }

        .section-header h2 {
            font-size: 18px;
        }

        .filter-options {
            display: flex;
            gap: 12px;
        }

        .filter-btn {
            background: var(--light-gray);
            border: none;
            padding: 6px 12px;
            border-radius: 16px;
            font-size: 13px;
            color: var(--gray);
        }

        .filter-btn.active {
            background: var(--primary);
            color: var(--white);
        }

        .restaurant-list {
            display: grid;
            gap: 20px;
        }

        .restaurant-card {
            background: var(--white);
            border-radius: var(--radius);
            overflow: hidden;
            box-shadow: var(--shadow);
        }

        .restaurant-image {
            width: 100%;
            height: 160px;
            object-fit: cover;
        }

        .restaurant-info {
            padding: 12px;
        }

        .restaurant-header {
            display: flex;
            justify-content: space-between;
            margin-bottom: 8px;
        }

        .restaurant-name {
            font-weight: 600;
            font-size: 16px;
        }

        .rating {
            display: flex;
            align-items: center;
            background: var(--light-gray);
            padding: 2px 8px;
            border-radius: 12px;
        }

        .rating i {
            color: #ffb400;
            font-size: 12px;
            margin-right: 4px;
        }

        .restaurant-details {
            display: flex;
            font-size: 13px;
            color: var(--gray);
            margin-bottom: 8px;
        }

        .restaurant-details div {
            margin-right: 12px;
        }

        .restaurant-tags {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin-top: 8px;
        }

        .tag {
            font-size: 12px;
            padding: 2px 8px;
            border-radius: 4px;
        }

        .discount-tag {
            background: #fff0e6;
            color: var(--primary);
        }

        .fast-tag {
            background: #e6f7ff;
            color: var(--secondary);
        }

        .bottom-nav {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background: var(--white);
            display: flex;
            justify-content: space-around;
            padding: 12px 0;
            box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
        }

        .nav-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            text-decoration: none;
            color: var(--gray);
            font-size: 12px;
        }

        .nav-item.active {
            color: var(--primary);
        }

        .nav-item i {
            font-size: 20px;
            margin-bottom: 4px;
        }

        .recommended-section {
            background: var(--white);
            padding: 16px;
            margin-top: 16px;
            border-radius: var(--radius);
            box-shadow: var(--shadow);
        }

        .recommended-header {
            display: flex;
            align-items: center;
            margin-bottom: 16px;
        }

        .recommended-header i {
            color: var(--primary);
            margin-right: 8px;
            font-size: 18px;
        }

        .recommended-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 16px;
        }

        .recommended-item {
            border-radius: var(--radius);
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        }

        .recommended-item img {
            width: 100%;
            height: 120px;
            object-fit: cover;
        }

        .recommended-info {
            padding: 10px;
        }

        .recommended-info h4 {
            font-size: 14px;
            margin-bottom: 4px;
        }

        .recommended-info p {
            font-size: 12px;
            color: var(--gray);
        }

        .price {
            color: var(--primary);
            font-weight: 600;
            margin-top: 4px;
        }

        .ad-label {
            position: absolute;
            top: 10px;
            right: 10px;
            background: rgba(0,0,0,0.7);
            color: white;
            font-size: 10px;
            padding: 2px 6px;
            border-radius: 4px;
        }
    </style>
</head>
<body data-require-login="true">
<!-- 顶部导航 -->
<header class="header">
    <div class="location-bar">
        <div class="location">
            <i class="fas fa-map-marker-alt"></i>
            <span id="address">定位中...</span>
        </div>
        <div class="user-section" style="display: flex; align-items: center; gap: 10px;">
            <span id="username" style="color: #333; font-size: 14px; display: none;"></span>
            <button id="logoutBtn" style="background: #ff6b00; color: white; border: none; padding: 6px 12px; border-radius: 16px; font-size: 12px; cursor: pointer; display: none;">退出</button>
            <i class="fas fa-bell"></i>
        </div>
    </div>
    <div class="search-bar">
        <i class="fas fa-search"></i>
        <input type="text" placeholder="搜索商家、美食">
        <i class="fas fa-microphone"></i>
    </div>
</header>

<!-- 促销区域 -->
<section class="promo-section">
    <div class="promo-title">
        <h2>今日优惠</h2>
        <a href="discounted_activities.html">查看全部 <i class="fas fa-angle-right"></i></a>
    </div>
    <div class="promo-cards" id="promoCards">
        <!-- 动态插入优惠券卡片 -->
    </div>
</section>

<!-- 分类导航 -->
<section class="category-section">
    <div class="categories">
        <div class="category">
            <div class="category-icon">
                <i class="fas fa-utensils"></i>
            </div>
            <span class="category-name">快餐便当</span>
        </div>
        <div class="category">
            <div class="category-icon">
                <i class="fas fa-mug-hot"></i>
            </div>
            <span class="category-name">奶茶饮品</span>
        </div>
        <div class="category">
            <div class="category-icon">
                <i class="fas fa-bread-slice"></i>
            </div>
            <span class="category-name">面包甜点</span>
        </div>
        <div class="category">
            <div class="category-icon">
                <i class="fas fa-apple-alt"></i>
            </div>
            <span class="category-name">水果生鲜</span>
        </div>
        <div class="category">
            <div class="category-icon">
                <i class="fas fa-store"></i>
            </div>
            <span class="category-name">超市便利</span>
        </div>
    </div>
</section>

<!-- 商家列表 -->
<section class="restaurant-section">
    <div class="section-header">
        <h2>附近商家</h2>
        <div class="filter-options">
            <button class="filter-btn active">综合排序</button>
            <button class="filter-btn">速度最快</button>
            <button class="filter-btn">评分最高</button>
        </div>
    </div>

    <div class="restaurant-list">
        <!-- 商家卡片 1 -->
        <div class="restaurant-card">
            <img src="https://images.unsplash.com/photo-1552566626-52f8b828add9?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=300&w=400" alt="餐厅" class="restaurant-image">
            <div class="restaurant-info">
                <div class="restaurant-header">
                    <h3 class="restaurant-name">川湘小馆</h3>
                    <div class="rating">
                        <i class="fas fa-star"></i>
                        <span>4.8</span>
                    </div>
                </div>
                <div class="restaurant-details">
                    <div>月售 1245</div>
                    <div>30分钟送达</div>
                    <div>¥25起送</div>
                </div>
                <div class="restaurant-tags">
                    <span class="tag discount-tag">满30减12</span>
                    <span class="tag fast-tag">配送准时</span>
                </div>
            </div>
        </div>

        <!-- 商家卡片 2 -->
        <div class="restaurant-card">
            <img src="https://images.unsplash.com/photo-1554679665-f5537f187268?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=300&w=400" alt="餐厅" class="restaurant-image">
            <div class="restaurant-info">
                <div class="restaurant-header">
                    <h3 class="restaurant-name">麦香堡</h3>
                    <div class="rating">
                        <i class="fas fa-star"></i>
                        <span>4.7</span>
                    </div>
                </div>
                <div class="restaurant-details">
                    <div>月售 986</div>
                    <div>20分钟送达</div>
                    <div>¥20起送</div>
                </div>
                <div class="restaurant-tags">
                    <span class="tag discount-tag">新客立减10元</span>
                    <span class="tag fast-tag">极速配送</span>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- 猜你喜欢 -->
<section class="restaurant-section">
    <div class="section-header">
        <h2>猜你喜欢</h2>
    </div>

    <div class="recommended-section">
        <div class="recommended-header">
            <i class="fas fa-heart"></i>
            <h3>根据您的口味推荐</h3>
        </div>

        <div class="recommended-grid">
            <div class="recommended-item">
                <img src="https://images.unsplash.com/photo-1565299624946-b28f40a0ae38?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=300&w=300" alt="推荐菜品">
                <div class="recommended-info">
                    <h4>意式海鲜披萨</h4>
                    <p>芝士浓郁，海鲜丰富</p>
                    <div class="price">¥68</div>
                </div>
            </div>

            <div class="recommended-item">
                <img src="https://images.unsplash.com/photo-1563379926898-05f4575a45d8?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=300&w=300" alt="推荐菜品">
                <div class="recommended-info">
                    <h4>泰式冬阴功汤</h4>
                    <p>酸辣开胃，地道风味</p>
                    <div class="price">¥42</div>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- 底部导航 -->
<nav class="bottom-nav">
    <a href="first.html" class="nav-item active">
        <i class="fas fa-home"></i>
        <span>首页</span>
    </a>
    <a href="find.html" class="nav-item">
        <i class="fas fa-search"></i>
        <span>发现</span>
    </a>
    <a href="order.html" class="nav-item">
        <i class="fas fa-file-invoice"></i>
        <span>订单</span>
    </a>
    <a href="me.html" class="nav-item">
        <i class="fas fa-user"></i>
        <span>我的</span>
    </a>
</nav>

<script>
    // 自动定位并显示详细地址（高德地图API）
    function showAddress(address) {
        document.getElementById('address').innerText = address;
    }
    function getLocationAndShow() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function(position) {
                var lat = position.coords.latitude;
                var lng = position.coords.longitude;
                // 调用高德逆地理编码API
                var url = `https://restapi.amap.com/v3/geocode/regeo?location=${lng},${lat}&key=4dafc78c6d67551fea68e0c2f6c67626&output=json`;
                fetch(url)
                    .then(res => res.json())
                    .then(data => {
                        if (data.status === "1") {
                            showAddress(data.regeocode.formatted_address);
                        } else {
                            showAddress("定位失败");
                        }
                    })
                    .catch(() => showAddress("定位失败"));
            }, function(error) {
                showAddress("用户拒绝定位");
            });
        } else {
            showAddress("浏览器不支持定位");
        }
    }
    // 动态渲染优惠券
    function renderCoupons(coupons) {
        const container = document.getElementById('promoCards');
        container.innerHTML = '';
        if (!coupons || coupons.length === 0) {
            container.innerHTML = '<div style="color:#999;">暂无优惠券</div>';
            return;
        }
        coupons.forEach(coupon => {
            container.innerHTML += `
                <div class="promo-card">
                    <h3>${coupon.title || coupon.name || '优惠券'}</h3>
                    <p>${coupon.description || ''}</p>
                    <span class="tag">${coupon.tag || '优惠'}</span>
                </div>
            `;
        });
    }
    window.onload = function() {
        getLocationAndShow();
        // 获取优惠券数据并渲染
        fetch('/api/coupons')
            .then(res => res.json())
            .then(data => {
                renderCoupons(data);
            })
            .catch(() => {
                renderCoupons([]);
            });
        // 简单的交互效果
        document.addEventListener('DOMContentLoaded', function() {
            // 筛选按钮交互
            const filterButtons = document.querySelectorAll('.filter-btn');
            filterButtons.forEach(button => {
                button.addEventListener('click', function() {
                    filterButtons.forEach(btn => btn.classList.remove('active'));
                    this.classList.add('active');
                });
            });
            // 模拟商家卡片点击
            const restaurantCards = document.querySelectorAll('.restaurant-card');
            restaurantCards.forEach(card => {
                card.addEventListener('click', function() {
                    alert('跳转到商家页面');
                });
            });
            // 定位功能模拟
            const locationElement = document.querySelector('.location');
            locationElement.addEventListener('click', function() {
                alert('打开地址选择器');
            });
        });
        if (typeof window.authOnload === 'function') window.authOnload();
    };
</script>
</body>
</html>